﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IFDB.Models;
using IFDB.Models.Contexts;
using IFDB.Models.Tables;
using IFDB.Repositories.Foundation;
using IFDB.ResourceLibrary;

namespace IFDB.Repositories.Application
{
    public class VenueRepository : Repository
    {
        public VenueRepository(IFDBContext db) 
            : base(db)
        {
        }

        public Venue FindVenue(Country country, string venueName)
        {
            IQueryable<Venue> venues = from v in db.Venues
                                       where v.VenueName == venueName && v.Country == country
                                       select v;

            if (venues.Count() != 1)
                return null;
            else
                return venues.Single();
        }

        #region Inserts
        public Guid AddVenue(Country country, string venueName)
        {
            Guid newId = Guid.NewGuid();
            db.Venues.Add(new Venue() 
            { 
                VenueId = newId,
                Country = country, 
                VenueName = venueName });

            return newId;
        }
        #endregion
    }
}
